---@diagnostic disable: undefined-field, param-type-mismatch
local extension=Package("xiaobai-eleven")
extension.extensionName="xiaobai"

Fk:loadTranslationTable{
    ["xiaobai-eleven"]="十一届小白杯",
    
}
local U = require "packages/utility/utility"
local DIY = require "packages/diy_utility/diy_utility"

--[[]
--一个记录打印武将名及其翻译的函数，打印到packages/xiaobai/name.txt里
local whitelist={"moepack","hegemony","rbaijiang","hanqing","xiaobai","bshighlights","aaa_fengqi","aaa_fenghou",
"sashiko","tyj","teyvat_travel_log","aaa_steam","tuntian_studio","ol"}
local function PrintGeneralNames()
  local file = io.open("packages/xiaobai/name.txt", "w")
  if not file then return end
  
  for _, pack in ipairs(whitelist) do
    local extension = Fk.extensions[pack]
    if extension then
      for _, package_name in ipairs(extension) do
        local ps=Fk.packages[package_name]
        if ps and #ps.generals > 0 then
          for __, gen in ipairs(ps.generals) do
            local name = gen.name
            local trans = Fk.translations["zh_CN"][name] or ""
            file:write(string.format("%s ,%s\n", name, trans))
          end
        end
      end
    end

  end
  
  file:close()
end

local print_names = fk.CreateTriggerSkill{
  name = "#print_general_names",
  events = {fk.GameStart},
  global = true,
  can_trigger = function() return true end,
  on_cost = function() return true end,
  on_use = function() 
    PrintGeneralNames() 
    
  end,
}

Fk:addSkill(print_names)

--]]

local function AddWinAudio(general)
  local Win = fk.CreateActiveSkill{ name = general.name.."_win_audio" }
  Win.package = extension
  Fk:addSkill(Win)
end

local lizhaoyi = General(extension, "xiaobai-eleven__lizhaoyi", "shu", 3, 3, General.Female)


Fk:loadTranslationTable{
    ["xiaobai-eleven__lizhaoyi"]="李昭仪",
    ["#xiaobai-eleven__lizhaoyi"]="兰艾同烬",
    ["illustrator:xiaobai-eleven__lizhaoyi"]="凝聚永恒",
    ["designer:xiaobai-eleven__lizhaoyi"]="小叶子",
    ["cv:xiaobai-eleven__lizhaoyi"] = "桃妮儿",

    ["~xiaobai-eleven__lizhaoyi"] = "我不能受二三屈辱。"
}

local zhifen = fk.CreateViewAsSkill{
  name = "xiaobai__zhifen",
  anim_type = "offensive",
  pattern = "slash|duel",
  prompt = "#xiaobai__zhifen",
  interaction = function(self)
    local all_names = {"slash", "duel"}
    local names = U.getViewAsCardNames(Self, self.name, all_names)
    if  Self:getMark("@@xiaobai__zhifen-onlyslash")>0 then
      table.removeOne(names, "duel")
    end
    if Self:getMark("@@xiaobai__zhifen-onlyduel") >0 then
      table.removeOne(names, "slash")
    end
    if #names > 0 then
      return U.CardNameBox { choices = names, all_choices = all_names }
    end
  end,
  card_filter = function(self, to_select, selected)
    if #selected > 3 then return false end
    
    local handcards = Self:getCardIds("h")
    if #selected==0 and #handcards == 1 and  Self:getMark("@@xiaobai__zhifen-three")==0 then
      return true
    end
    
    return #selected<3 and Self:getMark("@@xiaobai__zhifen-one")==0
  end,
  
  view_as = function(self, cards)
      if  not self.interaction.data then return end
      local n=#Self:getCardIds("h")
      if not (#cards==1 and n==1 or #cards==3)then return end
      local card = Fk:cloneCard(self.interaction.data)
      card.skillName = self.name
      card:addSubcards(cards)
      return card
    end,
  before_use = function (self, player, use)
      local room = player.room
      local choices={"zhifen_type","zhifen_name","zhifen_beishui"}
      local choice = player.room:askForChoice(player, choices, self.name,
      "#xiaobai__zhifen-invoke")
      if choice=="zhifen_beishui" then
          use.card.extra_data= use.card.extra_data or {}
          table.insert(use.card.extra_data, "shifen_beishui")

        
      end
      local marks={"@@xiaobai__zhifen-onlyslash","@@xiaobai__zhifen-onlyduel","@@xiaobai__zhifen-three","@@xiaobai__zhifen-one"}
      for _,mark in ipairs(marks) do
        room:setPlayerMark(player, mark, 0)
      end
      if choice~="zhifen_type" then
          if use.card.name=="slash" then
              room:setPlayerMark(player, "@@xiaobai__zhifen-onlyduel", 1)
          elseif use.card.name=="duel" then
              room:setPlayerMark(player, "@@xiaobai__zhifen-onlyslash", 1)
          end
      end
      if choice~="zhifen_name" then
          local n=#use.card.subcards
          if #use.card.subcards==1 then
            room:setPlayerMark(player, "@@xiaobai__zhifen-three", 1)
          elseif #use.card.subcards==3 then
            room:setPlayerMark(player, "@@xiaobai__zhifen-one", 1)
          end
      end
    end,
  enabled_at_play = Util.TrueFunc;
  enabled_at_response = Util.FalseFunc;
}
local zhifen_targetmod= fk.CreateTargetModSkill{
  name = "#xiaobai__zhifen_targetmod",
  frequency = Skill.Compulsory,
  bypass_times = function(self, player, skill, scope, card)

    return card and table.contains(card.skillNames, zhifen.name)
    
  end,
}

local zhifen_trigger = fk.CreateTriggerSkill{
  name = "#xiaobai__zhifen_trigger",
  mute = true,
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player  and data.card and data.card.extra_data and table.contains(data.card.extra_data, "shifen_beishui") and data.to~=player
  end,
  on_cost = function(self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke("xiaobai__zhifen")
    room:notifySkillInvoked(player, "xiaobai__zhifen")

    data.damage = data.damage + 1
  end,
}
zhifen:addRelatedSkill(zhifen_trigger)
zhifen:addRelatedSkill(zhifen_targetmod)
lizhaoyi:addSkill(zhifen)
Fk:loadTranslationTable{
  ["xiaobai__zhifen"] = "鸷刎",
  [":xiaobai__zhifen"] = [[你可以将三张牌或最后一张手牌当作无次数限制的【杀】或【决斗】使用，然后你选择一项：
  1.下次仅能以另一种方式转化；2.下次仅能转化为另一种牌名。背水：此牌对其他角色造成的伤害+1。"]],
  ["zhifen_type"] = "下次仅能以另一种方式转化",
  ["zhifen_name"] = "下次仅能转化为另一种牌名",
  ["zhifen_beishui"] = "背水：此牌造成的伤害+1",
  ["@@xiaobai__zhifen-onlyslash"] = "仅能转化杀",
  ["@@xiaobai__zhifen-onlyduel"] = "仅能转化决斗",
  ["@@xiaobai__zhifen-three"] = "仅能转化三张牌",
  ["@@xiaobai__zhifen-one"] = "仅能转化最后一张牌",
  ["#xiaobai__zhifen"] = "鸷刎：你可以将三张牌或最后一张手牌当作无次数限制的【杀】或【决斗】使用。",
  ["#xiaobai__zhifen_targetmod"] = "鸷刎",
  ["#xiaobai__zhifen-invoke"] = "鸷刎：请选择！",

  ["$xiaobai__zhifen2"] = "君非梁鸿，然妾心三冬无改、万苦难移。",
  ["$xiaobai__zhifen1"] = "心非草木，今名登鬼录，必衔怨以报！",
}
local minning = fk.CreateTriggerSkill{
  name = "xiaobai__minning",
  events = {fk.EnterDying},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
    and player.maxHp ~= #player:getCardIds("h")
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, data)
  end,

  on_use = function(self, event, target, player, data)
    local room = player.room
    -- 摸牌至体力上限
    local maxHp = player.maxHp
    local handcardNum = #player:getCardIds("h")
    local n = handcardNum - maxHp
    if n > 0 then
      room:askForDiscard(player, n, n, false, self.name, false)
    elseif n < 0 then
      player:drawCards(-n, self.name)
    end
    
    -- 选择横置两名角色
    local ts=table.filter(room.alive_players, function(p)
      return not p.chained
    end)
    if #ts==0 then return end
    local targets = room:askForChoosePlayers(player, table.map(ts, function(p)
      return p.id end), 2, 2, "#xiaobai__minning-choose", self.name, true)
    
    if targets then
      for _, p in ipairs(targets) do
        local tar = room:getPlayerById(p)
        tar:setChainState(true)
      end
      
      -- 若包含自己则回复1点体力
      if table.contains(targets, player.id) then
        room:recover({
          who = player,
          num = 1-player.hp,
          recoverBy = player,
          skillName = self.name
        })
      end
    end
  end,
}

lizhaoyi:addSkill(minning)

Fk:loadTranslationTable{
  ["xiaobai__minning"] = "泯念",
  [":xiaobai__minning"] = [[每回合限一次，你进入濒死状态时，你可以将手牌调整至体力上限，然后至多横置两名角色，若其中包含你，则你将体力回复至1。]],
  ["#xiaobai__minning-choose"] = "泯念：选择两名角色，令其横置",
  ["xiaobai__jufen"] = "俱焚",
  [":xiaobai__jufen"] = "限定技，出牌阶段，若你没有手牌，你可以对自己造成1点火焰伤害，然后获得本回合进入弃牌堆的所有牌。",
  

  ["$xiaobai__minning1"] = "尽子规之血，竭邛赤之水，念念难忘…",
  ["$xiaobai__minning2"] = "琼田路渺，仙草难寻，岂是寡缘？",

  ["$xiaobai__jufen1"] = "含垢忍耻丈夫事，殉死国难女子亦可为。",
  ["$xiaobai__jufen2"] = "节可成不可毁，玉可焚不可辱。",
}
local jufen = fk.CreateActiveSkill{
  name = "xiaobai__jufen",
  anim_type = "offensive",
  prompt = "你可以对自己造成1点火焰伤害，然后获得本回合进入弃牌堆的所有牌。",
  frequency = Skill.Limited,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and
           #player:getCardIds("h") == 0
  end,
  
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:damage({
      from = player,
      to = player,
      damage = 1,
      damageType = fk.FireDamage,
      skillName = self.name,
    })
    local cards = {}
    room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
      for _, move in ipairs(e.data) do
        if move.toArea == Card.DiscardPile then
          for _, info in ipairs(move.moveInfo) do
            table.insertIfNeed(cards, info.cardId)
          end
        end
      end
    end, Player.HistoryTurn)
    cards = table.filter(cards, function (id)
      return table.contains(room.discard_pile, id)
    end)
    room:moveCards({
      ids = cards,
      toArea = Card.PlayerHand,
      to = player.id,
      moveReason = fk.ReasonPrey,
      skillName = self.name,
    })
  end,
}
lizhaoyi:addSkill(jufen)
local dengfuren = General(extension, "xiaobai-eleven__dengfuren", "wu", 3, 3, General.Female)
Fk:loadTranslationTable{
  ["xiaobai-eleven__dengfuren"] = "邓夫人",
  ["#xiaobai-eleven__dengfuren"] = "绮蕊点绛",
  ["designer:xiaobai-eleven__dengfuren"] = "食马者",
  ["illustrator:xiaobai-eleven__dengfuren"] = "执兮",
}

local dianchi = fk.CreateTriggerSkill{
  name = "xiaobai__dianchi",
  anim_type = "drawcard",
  switch_skill_name = "xiaobai__dianchi",
  events = {fk.HpChanged},
  can_trigger = function(self, event, target, player, data)
    if not (target == player and player:hasSkill(self.name)) then return end
    if player:getSwitchSkillState(self.name, false) == fk.SwitchYang then
      -- 阳：体力变化为1后
      if player.hp == 1 then
        return true
      end
    else
      -- 阴：回复体力至上限后
      if data.num > 0 and player.hp == player.maxHp then
        return true
      end
    end
  end,
  
  on_use = function(self, event, target, player, data)
    local room = player.room
    local handcardNum = #player:getCardIds("h")
    if handcardNum < 4 then
      room:drawCards(player, 4 - handcardNum, self.name)
    end
  end,
}

local xiancu = fk.CreateActiveSkill{
  name = "xiaobai__xiancu",
  attached_skill_name = "xiaobai__xiancu&",
  can_use = function (self, player, card, extra_data)
    local c = Fk:cloneCard("peach")
    return player:isWounded() and not player:isProhibited(player,c)
  end,
  card_filter = function (self, to_select, selected, selected_targets)
    local suits = Self:getMark("@xiaobai__xiancu-turn")
    if type(suits) ~= "table" then
      suits = {}
    end
    if selected == nil or #selected == 0 then
      return not table.contains(suits,Fk:getCardById(to_select):getSuitString(true))
    end
    local c = Fk:cloneCard("peach")
    c:addSubcards(selected)
    c:addSubcard(to_select)
    return #selected < 2 and (not table.contains(suits,Fk:getCardById(to_select):getSuitString(true))) and Self:canUseTo(c,Self)
  end,
  card_num = 2,
  on_use = function (self, room, effect)
    local player = room:getPlayerById(effect.from)
    local c = Fk:cloneCard("peach")
    c:addSubcards(effect.cards)
    room:useCard{
      from = player.id,
      tos = {{player.id}},
      card = c,
    }
  end
}

local xiancu_other = fk.CreateActiveSkill{
  name = "xiaobai__xiancu&",
  can_use = function (self, player, card, extra_data)
    local c = Fk:cloneCard("peach")
    local target = table.find(Fk:currentRoom().alive_players,function (element, index, array)
      return element:hasSkill(xiancu)
    end)
    return target and target:isWounded() and not player:isProhibited(player,c)
  end,
  card_filter = function (self, to_select, selected, selected_targets)
    local suits = Self:getMark("@xiaobai__xiancu-turn")
    if type(suits) ~= "table" then
      suits = {}
    end
    if selected == nil or #selected == 0 then
      return not table.contains(suits,Fk:getCardById(to_select):getSuitString(true))
    end
    local c = Fk:cloneCard("peach")
    c:addSubcards(selected)
    c:addSubcard(to_select)
    return #selected < 2 and (not table.contains(suits,Fk:getCardById(to_select):getSuitString(true))) and not Self:prohibitUse(c)
  end,
  card_num = 2,
  on_use = function (self, room, effect)
    local target = table.find(room:getAlivePlayers(),function (element, index, array)
      return element:hasSkill(xiancu)
    end)
    local player = room:getPlayerById(effect.from)
    local c = Fk:cloneCard("peach")
    c:addSubcards(effect.cards)
    c.skillName = "xiaobai__xiancu"
    room:useCard{
      from = player.id,
      tos = {{target.id}},
      card = c,
    }
  end
}
Fk:addSkill(xiancu_other)

local xiancu_chooseCard = fk.CreateActiveSkill{
  mute = true,
  name = "xiancu_chooseCard",
  card_num = 2,
  card_filter = function (self, to_select, selected, selected_targets)
    local suits = Self:getMark("@xiaobai__xiancu-turn")
    if type(suits) ~= "table" then
      suits = {}
    end
    if selected == nil or #selected == 0 then
      return not table.contains(suits,Fk:getCardById(to_select):getSuitString(true))
    end
    local c = Fk:cloneCard("peach")
    c:addSubcards(selected)
    c:addSubcard(to_select)
    return #selected < 2 and (not table.contains(suits,Fk:getCardById(to_select):getSuitString(true))) and not Self:prohibitUse(c)
  end,
}

Fk:addSkill(xiancu_chooseCard)

local xiancu_trigger = fk.CreateTriggerSkill{
  name = "#xiancu_trigger",
  mute = true,
  events = {fk.AskForCardUse},
  can_trigger = function (self, event, target, player, data)
    local card = Fk:cloneCard("peach")
    return  (target == player and player:hasSkill(self)) and data.extraData.must_targets and #data.extraData.must_targets>0 
      and player.room:getPlayerById(data.extraData.must_targets[1]):hasSkill(xiancu) 
      and Exppattern:Parse(data.pattern):match(card)
  end,
  on_cost = function (self, event, target, player, data)
    local real,ret = player.room:askForUseActiveSkill(player,"xiancu_chooseCard","#xiancu_chooseCard::"..data.extraData.must_targets[1],true)
    if real and ret then
      self.cost_data = ret.cards
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local cards = self.cost_data
    target = table.find(player.room:getAlivePlayers(),function (element, index, array)
      return element:hasSkill(xiancu)
    end)
    local c = Fk:cloneCard("peach")
    c:addSubcards(cards)
    c.skillName = "xiaobai__xiancu"
    data.result = {
      from = player.id,
      card = c
    }
    return true
  end,
  refresh_events = {fk.AfterCardsMove, fk.EventAcquireSkill},
  can_refresh = function(self, event, target, player, data)
    if event == fk.AfterCardsMove then
      for _, move in ipairs(data) do
        if move.toArea == Card.DiscardPile then
          for _, info in ipairs(move.moveInfo) do
            if player.room:getCardArea(info.cardId) == Card.DiscardPile then
              return true
            end
          end
        end
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.DiscardPile and player.room:getCardArea(info.cardId) ~= Card.DiscardPile  then
            return true
          end
        end
      end
    else
      return data == self and player.room:getTag("RoundCount")
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardsMove then
      local ids = player:getTableMark("@xiaobai__xiancu-turn")
      for _, move in ipairs(data) do
        if move.toArea == Card.DiscardPile then
          for _, info in ipairs(move.moveInfo) do
            if room:getCardArea(info.cardId) == Card.DiscardPile then
              table.insertIfNeed(ids, Fk:getCardById(info.cardId):getSuitString(true))
            end
          end
        end
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.DiscardPile and room:getCardArea(info.cardId) ~= Card.DiscardPile then
            table.removeOne(ids, Fk:getCardById(info.cardId):getSuitString(true))
          end
        end
      end
      room:setPlayerMark(player, "@xiaobai__xiancu-turn", ids)
    else
      local ids = {}
      room.logic:getEventsOfScope(GameEvent.MoveCards, 999, function(e)
        for _, move in ipairs(e.data) do
          if move.toArea == Card.DiscardPile then
            for _, info in ipairs(move.moveInfo) do
              if room:getCardArea(info.cardId) == Card.DiscardPile then
                table.insertIfNeed(ids, Fk:getCardById(info.cardId):getSuitString(true))
              end
            end
          end
        end
      end, Player.HistoryTurn)
      room:setPlayerMark(player, "@xiaobai__xiancu-turn", ids)
    end
  end,
}
xiancu:addRelatedSkill(xiancu_trigger)
xiancu_other:addRelatedSkill(xiancu_trigger)

local xiaboai__quanxi = fk.CreateActiveSkill{
  name = "xiaobai__quanxi",
  anim_type = "support",
  prompt = "绻膝：你可以对一名角色视为使用一张【树上开花】，然后其对你造成1点伤害",
  card_filter = Util.FalseFunc,
  target_filter = function (self, to_select, selected, selected_cards, card, extra_data)
    return #selected < 1
  end,
  target_num = 1,
  on_use = function (self, room, effect)
    local target = room:getPlayerById(effect.tos[1])
    local player = room:getPlayerById(effect.from)
    room:useVirtualCard("bogus_flower",nil,player,{target},self.name,true)
    player.room:damage{
      from = target,
      to = player,
      damage = 1,
      skillName = self.name,
    }
  end
}

dengfuren:addSkill(xiancu)
dengfuren:addSkill(xiaboai__quanxi)
dengfuren:addSkill(dianchi)
Fk:loadTranslationTable{
  ["xiaobai__dianchi"] = "点赤",
  [":xiaobai__dianchi"] = "转换技，阳：当你的体力变化为1后；阴：当你回复体力至上限后，你将手牌摸至四张。",
  ["xiaobai__xiancu"] = "羡簇",
  ["@xiaobai__xiancu-turn"] = "羡簇",
  ["#xiancu_chooseCard"] = "羡簇：是否将两张与本回合进入弃牌堆花色均不同的牌当【桃】对 %dest 使用？",
  ["xiaobai__xiancu&"] = "羡簇",
  [":xiaobai__xiancu"] = "一名角色于其出牌阶段或你濒死对其求【桃】时，可以将两张与本回合进入弃牌堆花色均不同的牌当【桃】对你使用。",
  [":xiaobai__xiancu&"] = "一名角色于其出牌阶段或或你濒死对其求【桃】时，可以将两张与本回合进入弃牌堆花色均不同的牌当【桃】对你使用。",
  ["xiaobai__quanxi"] = "绻膝",
  [":xiaobai__quanxi"] = "出牌阶段，你可视为对一名角色使用【树上开花】然后受到其造成的1点伤害。"
}

local luyu = General(extension, "xiaobai-eleven__luyu", "wei", 3)

local jinti = fk.CreateActiveSkill{
  name = "xiaobai__jinti",
  anim_type = "offensive",
  dynamic_desc = function (self, player, lang)
    local xiangshu = player:getMark("xiaobai__jinti")
    local result = "xiaobai__jinti_inner:"
    local list = {}
    for i = 1,xiangshu-1,1 do
      table.insert(list,"#jinti-use")
    end
      table.insert(list,"#jinti-draw")
    for i = xiangshu+1,5,1 do
      table.insert(list,"#jinti-use")
    end
    return result..table.concat(list,":")
  end,
  can_use = function (self, player, card, extra_data)
    return player:usedSkillTimes(self.name,Player.HistoryPhase) == 0 and (player:getMark("xiaobai__jinti") == 1 or
    table.find(player:getHandlyIds(true), function(id)
      local card = Fk:getCardById(id)
      return player:canUse(card,{bypass_times = true}) and not player:prohibitUse(card)
    end))
  end,
  card_num = 0,
  card_filter = Util.FalseFunc,
  target_num = 0,
  target_filter = Util.FalseFunc,
  prompt = function (self, selected_cards, selected_targets)
    local player = Self
    if player == nil then
      return ""
    end
    local xiangshu = player:getMark("xiaobai__jinti")
    local result = Fk:translate("#jinti-start")
    for i = 1,xiangshu-1,1 do
      result = result + '  ' + i + "." +Fk:translate("#jinti-use")
    end
    result = result + '  ' + xiangshu + "." + Fk:translate("#jinti-draw")
    for i = xiangshu+1,5,1 do
      result = result + '  ' + i + "." +Fk:translate("#jinti-use")
    end
    return result
  end,
  on_use = function (self, room, effect)
    local player = room:getPlayerById(effect.from)
    local jinti_order = player:getMark("xiaobai__jinti")
    if jinti_order < 0 then
      jinti_order = 0
    end
    room:setPlayerMark(player,"xiaobai__jinti",0)
    for i = 1,5,1 do
      if i == jinti_order then
        if player:getHandcardNum()<4 then
          if not (room:askForSkillInvoke(player,self.name,nil,"#jinti-choose2draw4")) then
            break
          end 
        end
        local draw_num = 4 - player:getHandcardNum()
        if draw_num > 0 then
          player:drawCards(draw_num,self.name)
        end
        room:addPlayerMark(player,"xiaobai__jinti",1)
      elseif i < jinti_order then
          local use = U.askForPlayCard(room,player,nil,".",self.name,"#jinti-choose2Use",{bypass_times = true,extraUse = true})
          if not use then
            break
          else
            room:addPlayerMark(player,"xiaobai__jinti",1)
          end
      else
        local suits_mark = player:getMark("@xiaobai__jinti_suit-turn")
        local suits = {}
        if type(suits_mark) == "table" then 
          suits = table.map(suits_mark,function (element, index, array)
            return U.ConvertSuit(element,"sym","str")
          end)
        end
        local patterns = ".|.|^("..table.concat(suits,',') ..")"
        local use = U.askForPlayCard(room,player,nil,patterns,self.name,"#jinti-choose2Use")
        if not use then
          break
        else
          room:addPlayerMark(player,"xiaobai__jinti",1)
        end
      end
    end
    if player:getMark("xiaobai__jinti") == 0 then
      room:setPlayerMark(player,"xiaobai__jinti",jinti_order)
    end
  end
}

local jinti_record = fk.CreateTriggerSkill{
  name = "#xiaobai__jinti_record",
  refresh_events = {fk.CardUseFinished,fk.EventAcquireSkill,fk.GameStart},
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(self) and player:hasSkill(jinti)and (event~=fk.EventAcquireSkill or (data == jinti and target == player) )
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    if event == fk.CardUseFinished then
      local room = player.room
      local suit = data.card:getSuitString(true)
      local ids = player:getTableMark("@xiaobai__jinti_suit-turn") or {}
      if suit == "log_nosuit" then
        return
      end
      table.insertIfNeed(ids,suit)
      room:setPlayerMark(player, "@xiaobai__jinti_suit-turn", ids)
    elseif event == fk.EventAcquireSkill then
      local ids = {}
      room.logic:getEventsOfScope(GameEvent.UseCard, 999, function(e)
        local use = e.data[1] ---@type CardUseStruct
        if use.from ~= player.id then return false end
        local record = use.card:getSuitString(true)
        if record ~= "log_nosuit" then
          table.insertIfNeed(ids,record)
        end
      end, Player.HistoryTurn)
      if #ids > 0 then
        room:setPlayerMark(player, "@xiaobai__jinti_suit-turn", ids)
      end
      player.room:setPlayerMark(player,"xiaobai__jinti",1)
    else
      player.room:setPlayerMark(player,"xiaobai__jinti",1)
    end
  end
}

local lincai = fk.CreateTriggerSkill{
  name = "xiaobai__lincai",
  anim_type = "masochism",
  events = {fk.Damaged},
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = room.alive_players
    targets = table.filter(targets,function (element, index, array)
      return #element:getCardIds("e") <= player:getMark("xiaobai__jinti")-1
    end)
    targets = table.map(targets,Util.IdMapper)
    local to = room:askForChoosePlayers(player, targets, 1, 1, "#lincai-choose:::"..(player:getMark("xiaobai__jinti")-1), self.name, true)
    if #to > 0 then
      self.cost_data = {tos = to}
      return true
    end
    self.cancel_cost = true
  end,
  on_use = function(self, event, target, player, data)
    local to = player.room:getPlayerById(self.cost_data.tos[1])
    to:drawCards(2,self.name)
  end
}

jinti:addRelatedSkill(jinti_record)
luyu:addSkill(jinti)
luyu:addSkill(lincai)

Fk:loadTranslationTable{
  ["xiaobai-eleven__luyu"] = "卢毓",
  ["#xiaobai-eleven__luyu"] = "啄影哺弼",
  ["illustrator:xiaobai-eleven__luyu"] = "circle",
  ["designer:xiaobai-eleven__luyu"] = "胖宝宝",
  ["xiaobai__jinti"] = "进替",
  [":xiaobai__jinti"] = "出牌阶段限一次，你可以依次：摸牌至四张，使用一张牌，"..
    "使用一张牌，使用一张牌，使用一张牌。因此使用的牌于“摸牌至四张”前不受次数限制，之后需为本回合未被使用过的花色的牌。然后你交换“摸牌至四张”和最后执行的项。",
  [":xiaobai__jinti_inner"] = "出牌阶段限一次，你可以依次：{1}，{2}，"..
    "{3}，{4}，{5}。因此使用的牌于“摸牌至四张”前不受次数限制，之后需为本回合未被使用过的花色的牌。然后你交换“摸牌至四张”和最后执行的项。",
  ["@xiaobai__jinti_suit-turn"] = "进替",
  ["#jinti-start"] = "进替：你可以依次执行：",
  ["#jinti-use"] = "使用一张牌",
  ["#jinti-draw"] = "将手牌摸至四张",
  ["#jinti-choose2Use"] = "进替：你可以使用一张牌",
  ["#jinti-choose2draw4"] = "进替：你可以摸牌至4张（若已有至少四张牌则跳过此项）",
  ["xiaobai__lincai"] = "遴才",
  [":xiaobai__lincai"] = "当你受到伤害后，你可以令一名装备区牌数不大于X的角色摸两张牌（X为“进替”中“摸至四张”之前的项数）。",
  ["#lincai-choose"] = "遴才：你可以选择一名装备数不大于%arg的角色令其摸两张牌"
}

local lifeng = General(extension, "xiaobai-eleven__lifeng", "wei", 3)

local danming = fk.CreateTriggerSkill{
  name = "xiaobai__danming",
  anim_type = "drawcard",
  events = {fk.CardUseFinished},
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(self) and player:getHandcardNum() ~= 4 - player:getMark("@xiaobai__danming_reduce-round") and target == player
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player,self.name,nil,"#xiaobai__danming-use:::"..(4-player:getMark("@xiaobai__danming_reduce-round")))
  end,
  on_use = function (self, event, target, player, data)
    local num = 4- player:getMark("@xiaobai__danming_reduce-round") - player:getHandcardNum()
    if num > 0 then
      player:drawCards(num,self.name)
      if player:getMark("@xiaobai__danming_reduce-round") < 4 and player.room:askForSkillInvoke(player,self.name,nil,"#xiaobai__danming-continue") then
        player.room:addPlayerMark(player,"@xiaobai__danming_reduce-round",1)
      else
        player.room:delay(200)
        player.room:invalidateSkill(player,self.name,"-turn")
        player.room:addPlayerMark(player,"@@xiaobai__danming-invalid-turn")
      end
    else
      player.room:askForDiscard(player,-num,-num,false,self.name,false)
    end
  end
}

local youbai = fk.CreateTriggerSkill{
  name = "xiaobai__youbai",
  anim_type = "control",
  derived_piles = "dengai_field",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player:usedSkillTimes(self.name) == 0 then
      for _, move in ipairs(data) do
        if move.from == player.id and (move.moveReason ~= fk.ReasonUse and move.moveReason ~= fk.ReasonResonpse) then
          for _, info in ipairs(move.moveInfo) do
            if (info.fromArea == Card.PlayerHand) then
              return true
            end
          end
        end
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    if room:askForSkillInvoke(player,self.name) then
      local targets = room:getAlivePlayers()
      local maxNum,maxEquip = 0,0
      for _, p in ipairs(targets) do
        maxNum = math.max(maxNum, p:getHandcardNum())
        maxEquip = math.max(maxEquip,#p:getCardIds("e"))
      end
      local handcard_max = table.filter(targets, function(p) return p:getHandcardNum() == maxNum end)
      local equip_max = table.filter(targets, function(p) return #p:getCardIds("e") == maxEquip end)
      self.cost_data = {}
      self.cost_data.equiptarget = nil
      self.cost_data.handcardtarget = nil
      self.cost_data.equiptarget = room:askForChoosePlayers(player,table.map(equip_max,Util.IdMapper),1,1,"#youbai-equip",self.name)
      if self.cost_data.equiptarget then
        self.cost_data.handcardtarget = room:askForChoosePlayers(player,table.map(handcard_max,Util.IdMapper),1,1,"#youbai-handcard",self.name)
        return #self.cost_data.handcardtarget > 0
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:getPlayerById(self.cost_data.equiptarget[1]):drawCards(1,self.name)
    room:getPlayerById(self.cost_data.handcardtarget[1]):drawCards(1,self.name)
    if self.cost_data.equiptarget[1] ~= self.cost_data.handcardtarget[1] then
      local targets = room:askForChooseToMoveCardInBoard(player, "#youbai-move", self.name, true)
      if #targets ~= 0 then 
        room:askForMoveCardInBoard(player, room:getPlayerById(targets[1]), room:getPlayerById(targets[2]), self.name)
      end
    end
  end,

}
AddWinAudio(lifeng)
lifeng:addSkill(danming)
lifeng:addSkill(youbai)

Fk:loadTranslationTable{
  ["xiaobai-eleven__lifeng"] = "李丰",
  ["#xiaobai-eleven__lifeng"] = "蓬蒿易易",
  ["illustrator:xiaobai-eleven__lifeng"] = "错错知错",
  ["designer:xiaobai-eleven__lifeng"] = "小叶子",
  ["cv:xiaobai-eleven__lifeng"] = "小叶子",
  ["xiaobai__danming"] = "耽名",
  ["#xiaobai__danming-use"] = "耽名：你可以将手牌调整至%arg张",
  ["#xiaobai__danming-continue"] = "耽名：你可以令此技能数值本轮-1，或点“取消”令本回合此技能失效。",
  [":xiaobai__danming"] = "你使用一张牌后，可将手牌数调整至4，若因此摸牌，你选择一项：1、令此数值-1直至本轮结束。2、本回合此技能失效。",
  ["@xiaobai__danming_reduce-round"] = "耽名减少",
  ["@@xiaobai__danming-invalid-turn"] = "耽名失效",
  ["xiaobai__youbai"] = "游摆",
  ["#youbai-equip"] = "选择一名装备区牌数最多的角色",
  ["#youbai-handcard"] = "选择一名手牌数最多的角色",
  ["#youbai-move"] = "你可以移动场上一张牌",
  [":xiaobai__youbai"] = "每回合限一次，你不因使用或打出失去手牌后，你可以依次选择一名装备区牌数最多的角色与一名手牌数最多的角色各摸一张牌。若两者为不同角色，则你可以移动场上一张牌。",

  ["$xiaobai__danming1"] = "吾欲播名天下，当以才智示人。",
  ["$xiaobai__danming2"] = "君子矜于风姿，虽颓亦可登名。",
  ["$xiaobai__youbai1"] = "鼎秤易易，游于中庸可得万全。",
  ["$xiaobai__youbai2"] = "昭伯武威号施天下，仲达才略定策千军。",
  ["~xiaobai-eleven__lifeng"] = "卿父子怀奸，将倾社稷，惜吾力劣，不能相禽灭耳……",
  ["$xiaobai-eleven__lifeng_win_audio"] = "以殿下之明召，聚八方英豪，定剿司马全族!",
}

local yangyong = General(extension, "xiaobai-eleven__yangyong", "shu", 3)

local youjian = fk.CreateActiveSkill{
  name = "xiaobai__youjian",
  anim_type = "support",
  target_num = 1,
  card_num = 0,
  card_filter = Util.FalseFunc,
  target_filter = function (self, to_select, selected, selected_cards, card, extra_data)
    local target = Fk:currentRoom():getPlayerById(to_select)
    return #selected == 0 and target:getHandcardNum() > 0 and to_select ~= Self.id and Self:usedSkillTimes(self.name) == 0
  end,
  can_use = function (self, player, card, extra_data)
    return player:hasSkill(self) and player:getHandcardNum() > 0
  end,
  on_use = function (self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local self_card = player:getCardIds("h")
    local target_card = target:getCardIds("h")
    local chooseCards = U.askForExchange(player, "#TargetHand", "#SelfHand",target_card, self_card, "#yongjian-exchange", 2)
    if chooseCards == nil then
      return false
    end
    for index, value in ipairs(room:getAlivePlayers()) do
      if value:getMark("youjian") ~= 0 then
        room:setPlayerMark(value,"youjian",0)
      end
    end
    room:setPlayerMark(target,"youjian",1)
    local trans1 = table.filter(self_card,function (element, index, array)
      return table.contains(chooseCards,element)
    end)
    local trans2 = table.filter(target_card,function (element, index, array)
      return table.contains(chooseCards,element)
    end)
    U.swapCards(room,player,player,target,trans1,trans2,self.name)
    room:addPlayerMark(target,"@@youjian-turn")
    table.forEach(trans2,function (element, index, array)
      room:addCardMark(Fk:getCardById(element),"@@youjian-turn")
    end)
  end
}

local youjian_use = fk.CreateTriggerSkill{
  name = "#youjian_use",
  mute = true,
  events = {fk.CardUseFinished},
  can_trigger = function (self, event, target, player, data)
    if not (player:hasSkill(self) and player:hasSkill(youjian) and data.card.is_damage_card) then return false end
    return #table.filter(Card:getIdList(data.card), function(id)
      return Fk:getCardById(id):getMark("@@youjian-turn") > 0
    end) > 0 
  end,
  on_trigger = function (self, event, target, player, data)
    local num = #table.filter(Card:getIdList(data.card), function(id)
      return Fk:getCardById(id):getMark("@@youjian-turn") > 0
    end)
    for _ = 1, num, 1 do
      local tos = table.filter(player.room:getOtherPlayers(player),function (element, index, array)
        return element:getMark("@@youjian-turn") > 0
      end)
      for index, value in ipairs(tos) do
        self:doCost(event, value, player, data)
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player,self.name,nil,"#youjian-use::"..target.id)
  end,
  on_use = function (self, event, target, player, data)
    player:broadcastSkillInvoke("youjian")
    player:drawCards(1,self.name)
    target:drawCards(1,self.name)
  end
}

youjian:addRelatedSkill(youjian_use)

local zhongxi = fk.CreateTriggerSkill{
  name = "xiaobai__zhongxi",
  events = {fk.EventPhaseStart},
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(self) and target.phase == Player.Discard
  end,
  on_cost = function (self, event, target, player, data)
    local to = nil
    for index, value in ipairs(player.room:getAlivePlayers()) do
      if value:getMark("youjian") > 0 then
        to = value
        break
      end
    end
    if to == nil then
      return false
    end
    self.cost_data = {}
    if player.room.current == player then
      self.cost_data.from = player
      self.cost_data.to = to
    elseif player.room.current == to then
      self.cost_data.from = to
      self.cost_data.to = player
    else
      return false
    end
    local num = self.cost_data.from:getHandcardNum() - self.cost_data.from:getMaxCards()
    if num>0 then
      local cards = player.room:askForDiscard(self.cost_data.to,1,num,false,self.name,true,".","#zhongxi-use::"..self.cost_data.from.id..":"..num,true)
      if cards and #cards>0 then
        self.cost_data.cards = cards
        return true
      end
    end
    return false
  end,
  on_use = function (self, event, target, player, data)
    local to = self.cost_data.to
    local from = self.cost_data.from
    local room = player.room
    local cards = self.cost_data.cards
    local kongcheng = false
    if to:getHandcardNum() == #cards or #cards == self.cost_data.from:getHandcardNum() - self.cost_data.from:getMaxCards() then
      kongcheng = true
    end
    room:throwCard(cards,self.name,to,to)
    if to:isAlive() then
      room:addPlayerMark(from, MarkEnum.AddMaxCards.."-turn", #cards)
      if kongcheng then
        if room:askForSkillInvoke(player,self.name,nil,"#zhongxi-award::"..to.id) then
          if room:askForSkillInvoke(player,self.name,nil,"#zhongxi-recoverOrNot::"..to.id) then
            if to:isWounded() then
              room:recover({
                who = to,
                num = 1,
                recoverBy = player,
                skillName = self.name
              })
            end
          else
            to:drawCards(2,self.name)
          end
        end
      end
    end
  end
}

yangyong:addSkill(zhongxi)
yangyong:addSkill(youjian)

Fk:loadTranslationTable{
  ["xiaobai-eleven__yangyong"] = "杨颙",
  ["#xiaobai-eleven__yangyong"] = "惜相疲行",
  ["designer:xiaobai-eleven__yangyong"] = "小叶子",
  ["illustrator:xiaobai-eleven__yangyong"] = "查无",
  ["xiaobai__youjian"] = "忧谏",
  [":xiaobai__youjian"] = "出牌阶段限一次，你可以观看一名其他角色所有手牌并用至多两张手牌交换其中等量的牌。你于本回合使用以此获得的伤害牌后，可与其各摸一张牌。",
  ["#youjian-use"] = "你可以与 %dest 各摸一张牌各摸一张牌",
  ["@@youjian"] = "忧谏",
  ["@@youjian-turn"] = "忧谏",
  ["#yongjian-exchange"] = "忧谏：交换至多两张牌",
  ["xiaobai__zhongxi"] = "忠惜",
  ["#TargetHand"] = "对方手牌",
  ["#SelfHand"] = "你的手牌",
  [":xiaobai__zhongxi"] = "你/上次“忧谏”交换牌的目标的弃牌阶段开始时，其/你可以弃置至多X张手牌令你/其手牌上限增加等量，"..
    "然后你可以令因此弃置了X张或全部手牌的角色回复1点体力或摸两张牌(X为本回合角色需弃置的牌数)。",
  ["#zhongxi-award"] = "忠惜：你可以令 %dest 回复体力或摸两张牌",
  ["#zhongxi-recoverOrNot"] = "忠惜：你可以令 %dest 回复1点体力，或点击取消令其摸两张牌",
  ["#zhongxi-use"] = "忠惜：你可以弃置至多 %arg 令 %dest 本回合手牌上限增加等量"
}

local weidan = General:new(extension, "xiaobai-eleven__weidan", "wei", 3)

local jinmo = fk.CreateActiveSkill{
  name = "xiaobai__jinmo",
  can_use = function (self, player, card, extra_data)
    return #player:getCardIds("he")>0
  end,
  card_num = 1,
  card_filter = function (self, to_select, selected, selected_targets)
    return #selected == 0
  end,
  target_filter = Util.FalseFunc,
  on_use = function (self, room, effect)
    local player = room:getPlayerById(effect.from)
    local mark = player:getMark("@$xiaobai__jinmo-cards")
    if Fk:getCardById(effect.cards[1]).color == Card.Red  then
      player.room:invalidateSkill(player,self.name,"-phase")
      if type(mark) ~= "table" then room:throwCard(effect.cards,self.name,player) return end
      for _, value in ipairs(mark) do
        room:obtainCard(player,room:getCardsFromPileByRule(".|.|.|.|.|.|"..value,1,"discardPile"),true,fk.ReasonPrey,player.id,self.name)
      end
    end
    room:throwCard(effect.cards,self.name,player)
  end
}

local jinmo_mark = fk.CreateTriggerSkill{
  name = "#xiaobai__jinmo_mark",
  mute = true,
  refresh_events = {fk.AfterCardsMove,fk.EventAcquireSkill,fk.EventLoseSkill},
  frequency = Skill.Compulsory,
  can_refresh = function (self, event, target, player, data)
    if event == fk.AfterCardsMove then
      if (not player:hasSkill(self,true) )or (not player:hasSkill("xiaobai__jinmo",true)) then
        return false
      end
      for _, move in ipairs(data) do
        if #move.moveInfo == 1 and move.toArea == Card.DiscardPile then 
          return true
        end
      end
    elseif event == fk.EventAcquireSkill then
      return target == player and data == self
    else
      return target == player and data == self
    end
  end,
  on_refresh = function (self, event, target, player, data)
    if event == fk.AfterCardsMove then
      for _, move in ipairs(data) do
        if #move.moveInfo == 1 and move.toArea == Card.DiscardPile then
          for _, info in ipairs(move.moveInfo) do
            if Fk:getCardById(info.cardId).color == Card.Red then
              player.room:setPlayerMark(player,"@$xiaobai__jinmo-cards",0)
            else
              player.room:addTableMark(player,"@$xiaobai__jinmo-cards",info.cardId)
            end
          end
        end
      end
    elseif event == fk.EventAcquireSkill then
      player.room.logic:getEventsByRule(GameEvent.MoveCards,1,function (e)
        for _, move in ipairs(e.data) do
          if #move.moveInfo == 1 and move.toArea == Card.DiscardPile then
            for _, info in ipairs(move.moveInfo) do
              if Fk:getCardById(info.cardId).color == Card.Red then
                return true
              else
                player.room:addTableMark(player,"@$xiaobai__jinmo-cards",info.cardId)
              end
            end
          end
        end
      end,Player.HistoryGame)
    else
      player.room:setPlayerMark(player,"@$xiaobai__jinmo-cards",0)
    end
  end
}

jinmo:addRelatedSkill(jinmo_mark)

local yinhan = fk.CreateTriggerSkill{
  name = "xiaobai__yinhan",
  events = {fk.BeforeCardsMove,fk.CardRespondFinished},
  frequency = Skill.Compulsory,
  can_trigger = function (self, event, target, player, data)
    if (not player:hasSkill(self))  or player:getMark("@xiaobai__yinhan-color") == 0 then return false end
    if event == fk.BeforeCardsMove then
      for _, move in ipairs(data) do
        if move.from == player.id and move.moveReason == fk.ReasonUse then
          local use = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard,true).data[1]
          if (not use.card:isVirtual() or #use.card.subcards == 0) and use.card.type ~= Card.TypeEquip and use.card.sub_type ~= Card.SubtypeDelayedTrick then
            for _,info in ipairs(move.moveInfo) do
              if info.fromArea == Card.PlayerHand then
                return true
              end
            end
          end
        elseif move.from == player.id and move.moveReason == fk.ReasonResonpse and player:getMark("@xiaobai__yinhan-color") == "black" then
          return true
        elseif move.from == player.id and move.moveReason == fk.ReasonDiscard and player:getMark("@xiaobai__yinhan-color") == "red" then
          return true
        end
      end
    end
  end,
  on_use = function (self, event, target, player, data)
    if event == fk.BeforeCardsMove then
      if player:getMark("@xiaobai__yinhan-color") == "red" then
        for _, move in ipairs(data) do
          if move.moveReason == fk.ReasonUse then
            for _, info in ipairs(move.moveInfo) do
              DIY.HideCards(player,{info.cardId})
            end
            move.moveInfo = {}
          else
            for _, info in ipairs(move.moveInfo) do
              player.room:recastCard({info.cardId},player,self.name)
            end
            move.moveInfo = {}
          end
        end
      elseif player:getMark("@xiaobai__yinhan-color") == "black" then
        for _, move in ipairs(data) do
          if move.moveReason == fk.ReasonUse then
            for _, info in ipairs(move.moveInfo) do
              DIY.ShowCards(player,{info.cardId})
            end
            move.moveInfo = {}
          else 
            local others = player.room:getOtherPlayers(player)
            local cards = {}
            for _, move in ipairs(data) do
              if move.from == player.id and move.moveReason == fk.ReasonResonpse then
                for _, info in ipairs(move.moveInfo) do
                  table.insertIfNeed(cards,info.cardId)
                end
                move.moveInfo = {}
              end
            end
            if #cards == 0 then return end
            player.room:askForYiji(player,cards,others,self.name,#cards,#cards,"jinmo-give")
          end
        end
      end
    end
  end,
  refresh_events = {fk.AfterCardsMove,fk.EventAcquireSkill,fk.EventLoseSkill},
  can_refresh = function (self, event, target, player, data)
    if not player:hasSkill(self,true) then
      return event == fk.EventLoseSkill and data==self
    end
    if (event == fk.EventAcquireSkill and data == self) then
      return true
    end
    for _, move in ipairs(data) do
      if #move.moveInfo == 1 and move.toArea == Card.DiscardPile then
        return true
      end
    end
  end,
  on_refresh = function (self, event, target, player, data)
    if event == fk.EventLoseSkill then
      player.room:setPlayerMark(player,"@xiaobai__yinhan-color",0);
    elseif event == fk.EventAcquireSkill then
      player.room.logic:getEventsByRule(GameEvent.MoveCards,1,function (e)
        for _, move in ipairs(e.data) do
          if #move.moveInfo == 1 and move.toArea == Card.DiscardPile then
            for _, info in ipairs(move.moveInfo) do
              player.room:setPlayerMark(player,"@xiaobai__yinhan-color",Fk:getCardById(info.cardId):getColorString())
              return true
            end
          end
        end
      end,Player.HistoryGame)
    else
      for _, move in ipairs(data) do
        if #move.moveInfo == 1 and move.toArea == Card.DiscardPile then
          for _, info in ipairs(move.moveInfo) do
            player.room:setPlayerMark(player,"@xiaobai__yinhan-color",Fk:getCardById(info.cardId):getColorString())
          end
        end
      end
    end
  end
}

local yinhan_prohibited = fk.CreateProhibitSkill{
  name = "#yinhan_prohibited",
  prohibit_use = function(self, player, card)
    if player:getMark("@xiaobai__yinhan-color") == "black" then
      if card:getMark("@@ShownCards-inhand") > 0 then
        return true
      end
    elseif player:getMark("@xiaobai__yinhan-color") == "red" then
      if card:getMark("@@ShownCards-inhand") == 0 then
        return true
      end
    end
  end
}

yinhan:addRelatedSkill(yinhan_prohibited)

weidan:addSkill(jinmo)
weidan:addSkill(yinhan)
AddWinAudio(weidan)

Fk:loadTranslationTable{
  ["xiaobai-eleven__weidan"] = "韦诞",
  ["#xiaobai-eleven__weidan"] = "笔走凌云",
  ["designer:xiaobai-eleven__weidan"] = "易大剧",
  ["illustrator:xiaobai-eleven__weidan"] = "比目鱼",
  ["cv:xiaobai-eleven__weidan"] = "白小贝",
  ["xiaobai__jinmo"] = "浸墨",
  ["@$xiaobai__jinmo-cards"] = "浸墨",
  ["@xiaobai__yinhan-color"] = "引瀚",
  ["#yinhan_prohibited"] = "浸墨",
  ["jinmo-give"] = "浸墨：你需将这些牌交给任意名角色",
  [":xiaobai__jinmo"] = "出牌阶段，你可以弃置一张牌，若之为红色，你获得进入弃牌堆的与上一张红色牌（单张进入的）之间的所有黑色牌（单张进入的），且此技能本阶段失效。",
  ["xiaobai__yinhan"] = "引瀚",
  [":xiaobai__yinhan"] = "锁定技，若最后进入弃牌堆的是黑色牌，你以明置替代使用，以交给替代打出；反之，你以暗置替代使用，以重铸替代弃置。<a href=':xiaobai__yinhan1'>详细</a>",
  [":xiaobai__yinhan1"] = "若上一张单独进入弃牌堆的是黑色牌，你的非转化即时牌以明置替代使用，以交给其他角色替代打出手牌；"..
                          "若上一张单独进入弃牌堆的是红色牌，你的非转化即时牌以将明置牌改为暗置替代使用，以重铸手牌替代弃置手牌。<a href=':xiaobai__yinhan-detail'>怎么这么复杂？</a>",
  ["xiaobai__yinhan-detail"] = "引瀚",
  [":xiaobai__yinhan-detail"] = "看不懂此技能请私信问候EDG。\n<a href=':xiaobai__yinhan-real-detail'>如何问候？</a>",
  ["xiaobai__yinhan-real-detail"] = "引瀚",
  [":xiaobai__yinhan-real-detail"] = "易大剧：电话：+49（德）015259154728        QQ：814516560\n<a href=':xiaobai__yinhan-real-real-detail'>我真的只是想看看技能描述</a>",
  ["xiaobai__yinhan-real-real-detail"] = "引瀚",
  [":xiaobai__yinhan-real-real-detail"] = "①若上一张单独进入弃牌堆的是黑色牌：你无法使用明置牌；你的非转化即时牌暗置牌因使用而离开手牌区时，你取消之改为明置此牌；"..
                            "牌因打出离开你的手牌区时，你将此牌交给一名其他角色；"..
                          "②若上一张单独进入弃牌堆的是红色牌：你无法使用暗置牌；你的非转化即时明置牌因使用而离开手牌区时，你取消之改为暗置此牌；"..
                            "当你的牌因弃置而进入弃牌堆时，你取消之改为重铸此牌。",
  
  ["$xiaobai__jinmo1"] = "墨池飞鱼、笔锋族兔，成径丈之势。",
  ["$xiaobai__jinmo2"] = "笺麻素绢、石砚浮光，须臾落千言。",
  ["$xiaobai__yinhan1"] = "落笔不经意，动乃成云鹤。",
  ["$xiaobai__yinhan2"] = "作字同行兵，斧钺入体势。",
  ["~xiaobai-eleven__weidan"] = "子孙当戒，无为大字楷法。",
  ["$xiaobai-eleven__weidan_win_audio"] = "凌云题就、悬空俯瞰，河洛烟九点。"
}

local zhaoshuang = General(extension, "xiaobai-eleven__zhaoshuang", "wu", 3)
local gouxian = fk.CreateTriggerSkill{
  name = "xiaobai__gouxian",
  anim_type = "control",
  events = {fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and player.phase == Player.Play and #player.room.alive_players > 2 then
      local nums = {}
      for _, p in ipairs(player.room.alive_players) do
        if not p:isKongcheng() then
          table.insert(nums, p:getHandcardNum())
        end
      end
      if #nums < 3 then return end
      table.sort(nums, function (a, b)
        return a > b
      end)
      for i = 1, #nums - 2, 1 do
        if nums[i] < nums[i + 1] + nums[i + 2] then
          return true
        end
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local nums = {}
    for _, p in ipairs(player.room.alive_players) do
      if not p:isKongcheng() then
        table.insert(nums, p:getHandcardNum())
      end
    end
    if #nums < 3 then return end
    table.sort(nums, function (a, b)
      return a > b
    end)
    local yes, results = false, {}
    for i = 1, #nums - 2, 1 do
      for j = i + 1, #nums - 1, 1 do
        for k = j + 1, #nums, 1 do
          if nums[i] < nums[j] + nums[k] then
            yes = true
            if nums[j] == nums[i] or nums[j] == nums[k] then
              table.insert(results, {nums[i], nums[j], nums[k]})
            end
          end
        end
      end
    end
    local success, dat = nil,nil
    if yes and player:getHandcardNum() ~= 4 and room:askForSkillInvoke(player, self.name, nil, "#xiaobai__gouxian-invoke") then
      room:setPlayerMark(player, "xiaobai__gouxian-tmp", results)
      success, dat = room:askForUseActiveSkill(player, "xiaobai__gouxian_active", "#xiaobai__gouxian-choose", true, nil, false)
      room:setPlayerMark(player, "xiaobai__gouxian-tmp", 0)
      local n = player:getHandcardNum() - 4
      if n < 0 then
        player:drawCards(-n, self.name)
      else
        room:askForDiscard(player, n, n, false, self.name, false)
      end
    end
    if #results > 0 and not player.dead then
      if success and dat then
        room:delay(400)
        U.swapHandCards(room, player, room:getPlayerById(dat.targets[1]), room:getPlayerById(dat.targets[2]), self.name)
      end
    end
  end,
}
local gouxian_active = fk.CreateActiveSkill{
  name = "xiaobai__gouxian_active",
  card_num = 0,
  target_num = 2,
  card_filter = Util.FalseFunc,
  target_filter = function (self, to_select, selected)
    local results = Self:getMark("xiaobai__gouxian-tmp")
    local n = Fk:currentRoom():getPlayerById(to_select):getHandcardNum()
    if #selected == 0 then
      return table.find(results, function (dat)
        return table.contains(dat, n)
      end)
    elseif #selected == 1 then
      local n2 = Fk:currentRoom():getPlayerById(selected[1]):getHandcardNum()
      for _, dat in ipairs(results) do
        if table.contains(dat, n) and table.contains(dat, n2) then
          if n ~= n2 then
            return true
          elseif #table.filter(dat, function (i)
            return i == n
          end) > 1 then
            return true
          end
        end
      end
    end
  end,
}
local zhuotu = fk.CreateTriggerSkill{
  name = "xiaobai__zhuotu",
  anim_type = "special",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseProceeding},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Discard
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@@xiaobai__zhuotu", 1)
    local n = #table.filter(room.alive_players, function (p)
      return p:getHandcardNum() == 4
    end)
    if n > 0 and not player:isNude() then
      n = n * n
      room:askForDiscard(player, n, n, true, self.name, false)
    end
    player._phase_end = true
  end,

  refresh_events = {fk.TurnStart},
  can_refresh = function (self, event, target, player, data)
    return target == player and player:getMark("@@xiaobai__zhuotu") > 0
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "@@xiaobai__zhuotu", 0)
  end,
}
local zhuotu_delay = fk.CreateTriggerSkill{
  name = "#xiaobai__zhuotu_delay",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:getMark("@@xiaobai__zhuotu") > 0 and player:getHandcardNum() ~= 4 then
      for _, move in ipairs(data) do
        if move.from == player.id then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand then
              return true
            end
          end
        end
        if move.to == player.id and move.toArea == Card.PlayerHand then
          return true
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke("xiaobai__zhuotu")
    local n = player:getHandcardNum() - 4
    if n < 0 then
      room:notifySkillInvoked(player, "xiaobai__zhuotu", "drawcard")
      player:drawCards(-n, "xiaobai__zhuotu")
    else
      room:notifySkillInvoked(player, "xiaobai__zhuotu", "negative")
      room:askForDiscard(player, n, n, false, "xiaobai__zhuotu", false)
    end
  end,
}
Fk:addSkill(gouxian_active)
zhuotu:addRelatedSkill(zhuotu_delay)
zhaoshuang:addSkill(gouxian)
zhaoshuang:addSkill(zhuotu)

AddWinAudio(zhaoshuang)

Fk:loadTranslationTable{
  ["xiaobai-eleven__zhaoshuang"] = "赵爽",
  ["#xiaobai-eleven__zhaoshuang"] = "朱黄行者",
  ["illustrator:xiaobai-eleven__zhaoshuang"] = "查无",
  ["designer:xiaobai-eleven__zhaoshuang"] = "白小贝",
  ["cv:xiaobai-eleven__zhaoshuang"] = "超天酱",

  ["xiaobai__gouxian"] = "构弦",
  [":xiaobai__gouxian"] = "出牌阶段结束时，若场上有三名角色的手牌数能构成三角形，你可以将手牌数调整为4；若能构成等腰三角形，"..
  "你可以令其中两名角色交换手牌。",
  ["xiaobai__zhuotu"] = "琢图",
  [":xiaobai__zhuotu"] = "锁定技，你的弃牌阶段改为弃置X²张牌（X为场上手牌数为4的角色数，不足则全弃），直到你下个回合开始，"..
  "当你失去或获得手牌后，你将手牌数调整为4。",
  ["#xiaobai__gouxian-invoke"] = "构弦：是否将手牌数调整为4？",
  ["xiaobai__gouxian_active"] = "构弦",
  ["#xiaobai__gouxian-choose"] = "构弦：调整后你可以令手牌数构成等腰三角形角色中的两名角色交换手牌",
  ["@@xiaobai__zhuotu"] = "琢图",
  ["#xiaobai__zhuotu_delay"] = "琢图",

  ["~xiaobai-eleven__zhaoshuang"] = "图中尚有差疑，岂可轻生？",
  ["$xiaobai-eleven__zhaoshuang"] = "兼数形，验圆方，则可统叙群伦，裁制万物。",
  ["$xiaobai__gouxian1"] = "周公问天地之数，吾辈学者求之不倦。",
  ["$xiaobai__gouxian2"] = "迭相规矩，共为返覆，互与通分，各有所得。",
  ["$xiaobai__zhuotu1"] = "勾、股相乘为朱实二，倍之为朱实四。",
  ["$xiaobai__zhuotu2"] = "以形验数、形数为一，先贤之理可证矣。",
  ["$xiaobai-eleven__zhaoshuang_win_audio"] = "兼数形，验圆方，则可统叙群伦，裁制万物。"
}

local shenyiDuelSkill = fk.CreateActiveSkill{
  name = "duel",
  prompt = "#shenyi_duel-prompt",
  can_use = Util.CanUse,
  mod_target_filter = function(self, to_select, selected, player, card)
    return to_select ~= player.id
  end,
  target_filter = Util.TargetFilter,
  target_num = 1,
  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    local from = room:getPlayerById(effect.from)
    local responsers = { to, from }
    local do_changes = {false,false}
    local refuse = false
    local currentTurn = 1
    local currentResponser = to

    while currentResponser:isAlive() do
      local loopTimes = 1
      if effect.fixedResponseTimes then
        local canFix = currentResponser == to
        if effect.fixedAddTimesResponsors then
          canFix = table.contains(effect.fixedAddTimesResponsors, currentResponser.id)
        end

        if canFix then
          if type(effect.fixedResponseTimes) == 'table' then
            loopTimes = effect.fixedResponseTimes["slash"] or 1
          elseif type(effect.fixedResponseTimes) == 'number' then
            loopTimes = effect.fixedResponseTimes
          end
        end
      end
      local do_change = nil
      if currentResponser.kingdom ~= "wei" and not refuse then
        do_change = room:askForSkillInvoke(currentResponser,"duel",nil,"#shenyi_do_change_country")
        refuse = not do_change
        if refuse then
          effect.additionalDamage = (effect.additionalDamage or 0) + 1
        else
          room:changeKingdom(currentResponser,"wei",true)
          do_changes[currentTurn] = true
          if do_changes[1] and do_changes[2] then
            refuse = true
            room:drawCards(from,2,self.name)
            room:drawCards(to,2,self.name)
          end
        end
      end
      local cardResponded
      if not do_change then
        for i = 1, loopTimes do
          cardResponded = room:askForResponse(currentResponser, 'slash', nil, nil, true, nil, effect)
          if cardResponded then
            room:responseCard({
              from = currentResponser.id,
              card = cardResponded,
              responseToEvent = effect,
            })
          else
            break
          end
        end
      else
        cardResponded = true
      end

      if not cardResponded then
        break
      end

      currentTurn = currentTurn % 2 + 1
      currentResponser = responsers[currentTurn]
    end

    if currentResponser:isAlive() then
      room:damage({
        from = responsers[currentTurn % 2 + 1],
        to = currentResponser,
        card = effect.card,
        damage = 1,
        damageType = fk.NormalDamage,
        skillName = self.name,
      })
    end
  end
}

Fk:addSkill(shenyiDuelSkill)

local shenyi = General:new(extension, "xiaobai-eleven__shenyi", "wei", 4)
shenyi.subkingdom = "shu"

local beibian = fk.CreateViewAsSkill{
  name = "xiaobai__beibian",
  anim_type = "offensive",
  pattern = "duel",
  prompt = "shenyi_duel_use",
  card_filter = function (self, to_select, selected)
    local card = Fk:getCardById(to_select)
    return #selected < 1 and card.type ~= Card.TypeBasic and card:getTypeString() ~= Self:getMark("@beibian-type")
  end,
  card_num = 1,
  view_as = function (self, cards)
    if #cards > 1 or #cards == 0 then return nil end  
    local card = Fk:cloneCard("duel")
    card.skillName = self.name
    card.skill = shenyiDuelSkill
    card:addSubcards(cards)
    return card
  end,
  after_use = function (self, player, use)
    player.room:setPlayerMark(player,"@beibian-type",Fk:getCardById(use.card.subcards[1]):getTypeString())
  end
}
beibian:addAttachedKingdom("shu")

local nisi = fk.CreateTriggerSkill{
  name = "xiaobai__nisi",
  anim_type = "defensive",
  events = {fk.Damage,fk.Damaged},
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(self) and target == player and data.to ~= data.from and data.from ~= nil
  end,
  on_use = function (self, event, target, player, data)
    local players = {data.to,data.from}
    if data.to ~= player then
      players[2] = data.to
      players[1] = data.from
    end
    local room = player.room
    local choice_list = {"nisi-draw"}
    if players[2].kingdom ~= "shu"then
      choice_list = {"nisi-draw","nisi-changeKingdom"}
    end
    local choices = U.doStrategy(room, players[1], players[2], {"nisi-draw","nisi-changeKingdom"}, choice_list, self.name, 0,"nisi-choose")
    if choices[1] == "nisi-changeKingdom" then
      room:changeKingdom(players[1],"shu")
    else
      players[1]:drawCards(1,self.name)
    end
    if choices[2] == "nisi-changeKingdom" then
      room:changeKingdom(players[2],"shu")
    else
      players[2]:drawCards(1,self.name)
    end
    if choices[1] ~= choices[2] then
      if not players[2]:isNude() then
        local card = room:askForCardChosen(player,players[2],'he',self.name,"nisi-obtainCard")
        room:obtainCard(player,card,false)
      end
    end
  end

}
nisi:addAttachedKingdom("wei")

shenyi:addSkill(beibian)
shenyi:addSkill(nisi)

Fk:loadTranslationTable{
  ["xiaobai-eleven__shenyi"] = "申仪",
  ["#xiaobai-eleven__shenyi"] = "枕戈达旦",
  ["designer:xiaobai-eleven__shenyi"] = "食马者",
  ["illustrator:xiaobai-eleven__shenyi"] = "狗爷",
  ["cv:xiaobai-eleven__shenyi"] = "cyc",
  ["xiaobai__beibian"] = "狈变",
  [":xiaobai__beibian"] = "蜀势力技，你可以将一张非基本牌当【决斗】使用（此牌类型须与上次发动此技能转化用的底牌类型不同），"..
                          "此牌的响应方式添加“询问对方是否将势力变更至魏”直到一方拒绝/双方同意后，此牌伤害+1/双方各摸两张牌。",
  ["@beibian-type"] = "狈变",
  ["#shenyi_do_change_country"] = "决斗：是否变更势力至魏以相应此牌",
  
  ["shenyi_duel_use"] = "狈变:你可以将一张非基本牌当【决斗】使用，此【决斗】可以被“变更势力至魏”响应",
  ["xiaobai__nisi"] = "猊伺",
  [":xiaobai__nisi"] = "魏势力技，当你对其他角色造成或受到其他角色造成的伤害后，你可以与其同时选择一项:1.变更势力至蜀；2.摸一张牌；若你与其选择项不同，则你获得其一张牌。",
  ["nisi-draw"] = "摸一张牌",
  ["nisi-changeKingdom"] = "变更势力至蜀",
  [":nisi-changeKingdom"] = "若对方选择摸一张牌，申仪 可以获得对方一张牌。",
  [":nisi-draw"] = "若对方选择变更势力，申仪 可以获得对方一张牌。",
  ["nisi-choose"] = "猊伺：选择一项",
  ["nisi-obtainCard"] = "猊伺：获得其一张牌",

  ["$xiaobai__nisi1"] = "休执迷！皇叔破操，英雄归附，正合天意！",
  ["$xiaobai__nisi2"] = "《诗》云“自求多福”，在我而已，何求他人？",
  ["$xiaobai__beibian1"] = "魏王代汉，天地所兆，吾欲从之久矣！",
  ["$xiaobai__beibian2"] = "吾诚小人，虽不能始终，亦颇识去就之分。",
  ["~xiaobai-eleven__shenyi"] = "早知有命，浪走四方，何苦来哉？"
}

local louxuan = General(extension,"xiaobai-eleven__louxuan", "wu",3)

Fk:loadTranslationTable{
  ["xiaobai-eleven__louxuan"] = "楼玄",
  ["#xiaobai-eleven__louxuan"] = "松栽倒壑",
  ["designer:xiaobai-eleven__louxuan"] = "胖宝宝",
  ["illustrator:xiaobai-eleven__louxuan"] = "NOVART",
}

local linji_chooseCard = fk.CreateActiveSkill{
  name = "#linji_chooseCard",
  interaction = function (self)
    return UI.ComboBox{
      choices = {"Top","Bottom"},
      default = "Top"
    }
  end,
  prompt = "#linji_setCards",
  card_num = 2,
  card_filter = function (self, to_select, selected, selected_targets)
    return not selected or #selected<2
  end
}
Fk:addSkill(linji_chooseCard)

local linji = fk.CreateTriggerSkill{
  name = "xiaobai__linji",
  events = {fk.BeforeHpChanged},
  frequency = Skill.Compulsory,
  can_trigger = function (self, event, target, player, data)
    if target ~= player or not player:hasSkill(self) then
      return false
    end
    local evt = player.room.logic:getEventsOfScope(GameEvent.ChangeHp,2,function (e)
      if e.data[1] == player then
        return true
      end
    end,Player.HistoryTurn)
    return evt == nil or #evt < 2
  end,
  on_cost = function (self, event, target, player, data)
    local skill_target = player.room.current
    if #skill_target:getCardIds("he") < 2 then
      return 
    end
    local _,ret = player.room:askForUseActiveSkill(skill_target,"#linji_chooseCard","#linji_setCards",false)
    if not _ then return false end
    self.cost_data = {}
    self.cost_data.choice = 1
    if ret.interaction == "Bottom" then
      self.cost_data.choice = -1
    end
    self.cost_data.cards = ret.cards
    return true
  end,
  on_use = function (self, event, target, player, data)
    local skill_target = player.room.current
    local index = self.cost_data.choice
    local cards = self.cost_data.cards
    if cards and #cards>0 then
      player.room:moveCards({
        ids = cards,
        from = skill_target.id,
        toArea = Card.DrawPile,
        moveReason = fk.ReasonJustMove,
        skillName = "linji",
        drawPilePosition = index,
      })
    end
    local pos = "Top"
    if  index == 1 then pos = "Bottom" end
    if player.room:askForSkillInvoke(skill_target,self.name,nil,"#linji_askForDraw::"..player.id..":"..Fk:translate(pos)) then
      if index == 1 then
        skill_target:drawCards(2,self.name,"bottom")
      else
        skill_target:drawCards(2,self.name,"top")
      end
      return true
    end
  end
}

Fk:loadTranslationTable{
  ["xiaobai__linji"] = "凛脊",
  [":xiaobai__linji"] = "你的体力值每回合首次发生变化时，当前回合角色须将两张牌置于牌堆顶或牌堆底，"..
  "然后其可以从另一端摸两张牌，防止此体力变化。",
  ["#linji_chooseCard"] = "凛脊",
  ["#linji_setCards"] = "凛脊：将你的两张牌置于牌堆顶或牌堆底",
  ["#linji_askForDraw"] = "凛脊：是否从 %arg 摸两张牌防止 %dest 本次体力变化"
}

local lvgu_viewAndChoose = fk.CreateActiveSkill{
  name = "#lvgu_viewAndChoose",
  expand_pile = function (self)
    return Self:getTableMark("lvgu")
  end,
  interaction = function (self)
    local mark = Self:getTableMark("lvgu_choices")
    return UI.ComboBox{
      choices = mark.choices,
      all_choices = mark.all_choices
    }
  end,
  card_filter = function (self, to_select, selected, selected_targets)
    return false
  end,
}

Fk:addSkill(lvgu_viewAndChoose)

local lvgu = fk.CreateActiveSkill{
  name = "xiaobai__lvgu",
  can_use = function (self, player, card, extra_data)
    return #Fk:currentRoom().draw_pile > 0
  end,
  interaction = function (self)
    local all_choices = {"#lvgu_view1","#lvgu_view3"}
    local choices = {"#lvgu_view1"}
    if #Fk:currentRoom().draw_pile >= 3 then
      table.insert(choices,"#lvgu_view3")
    end
    return UI.ComboBox{
      choices = choices,
      all_choices = all_choices
    }
  end,
  card_filter = Util.FalseFunc,
  card_num = 0,
  on_use = function (self, room, effect)
    local player = room:getPlayerById(effect.from)
    local card_pile = room.draw_pile
    local choice = self.interaction.data
    if choice == "#lvgu_view1" then
      local all_choices = {
        "lvgu_changeHanCardThree","lvgu_Use","lvgu_loseHp",
      }
      local can_choices = {}

      room:setPlayerMark(player,"lvgu",{card_pile[#card_pile]})

      if not player:getMark("@@lvgu_one-turn") or player:getMark("@@lvgu_one-turn") == 0 then
        table.insert(can_choices,all_choices[1])
      end
      table.insert(can_choices,all_choices[2])
      table.insert(can_choices,all_choices[3])

      room:setPlayerMark(player,"lvgu_choices",{choices = can_choices,all_choices = all_choices})
      local _,ret = room:askForUseActiveSkill(player,"#lvgu_viewAndChoose","#lvgu_Choose",false)
      local chosen1 = ret.interaction 

      table.removeOne(can_choices,chosen1)

      room:setPlayerMark(player,"lvgu_choices",{choices = can_choices,all_choices = all_choices})
      _,ret = room:askForUseActiveSkill(player,"#lvgu_viewAndChoose","#lvgu_Choose",false)
      local chosen2 = ret.interaction

      if chosen1 == all_choices[1] or chosen2 == all_choices[1] then
        local num = player:getHandcardNum() - 3
        if num>0 then
          room:askForDiscard(player,num,num,false,self.name,false,".","lvgu_changeHanCardThree")
        elseif num < 0 then
          player:drawCards(-num,self.name)
        end
        room:setPlayerMark(player,"@@lvgu_one-turn",1)
      end
      if player.dead then return end


      if chosen1 == all_choices[2] or chosen2 == all_choices[2] then
        local cards = player:getTableMark("lvgu")
        U.askForUseRealCard(room,player,cards,"^(slash)",self.name,"#lvgu_useOne",{expand_pile = cards})
      end
      if player.dead then return end


      if chosen1 == all_choices[3] or chosen2 == all_choices[3] then
        room:loseHp(player,1,self.name)
      end
    else
      local all_choices = {
        "lvgu_changeHanCardOne","lvgu_Use","lvgu_loseHp",
      }
      local can_choices = {}

      if not player:getMark("@@lvgu_three-turn") or player:getMark("@@lvgu_three-turn") == 0 then
        table.insert(can_choices,all_choices[1])
      end
      table.insert(can_choices,all_choices[2])
      table.insert(can_choices,all_choices[3])

      local cards = table.slice(card_pile,#card_pile-2,#card_pile+1)
      room:setPlayerMark(player,"lvgu",cards)
      room:setPlayerMark(player,"lvgu_choices",{choices = can_choices,all_choices = all_choices})

      local _,ret = room:askForUseActiveSkill(player,"#lvgu_viewAndChoose","#lvgu_Choose",false)
      local chosen1 = ret.interaction 
      table.removeOne(can_choices,chosen1)

      room:setPlayerMark(player,"lvgu_choices",{choices = can_choices,all_choices = all_choices})
      _,ret = room:askForUseActiveSkill(player,"#lvgu_viewAndChoose","#lvgu_Choose",false)
      local chosen2 = ret.interaction

      if chosen1 == all_choices[1] or chosen2 == all_choices[1] then
        if player:getHandcardNum() == 0 then
          player:drawCards(1,self.name)
        else
          local num = player:getHandcardNum() - 1
          if num>0 then
            room:askForDiscard(player,num,num,false,self.name,false,".","lvgu_changeHanCardOne")
          end
        end
        room:setPlayerMark(player,"@@lvgu_three-turn",1)
      end
      if player.dead then return end

      if chosen1 == all_choices[2] or chosen2 == all_choices[2] then
        local cards = player:getTableMark("lvgu")
        U.askForUseRealCard(room,player,cards,"^(slash)",self.name,"#lvgu_useOne",{expand_pile = cards})
      end
      if player.dead then return end

      if chosen1 == all_choices[3] or chosen2 == all_choices[3] then
        room:loseHp(player,1,self.name)
      end
    end
    room:setPlayerMark(player,"lvgu_choices")
    room:setPlayerMark(player,"lvgu")
  end
}
Fk:loadTranslationTable{
  ["xiaobai__lvgu"] = "履骨",
  [":xiaobai__lvgu"] = "出牌阶段，你可以观看牌堆底一/三张牌，然后依次选择两项：1.调整手牌数至三/一(每回合各限选一次)；"..
                      "2.可使用其中一张不为【杀】的牌；3.失去1点体力。",
  ["#lvgu_view1"] = "观看牌堆底的一张牌",
  ["#lvgu_view3"] = "观看牌堆底的三张牌",
  ["lvgu_changeHanCardOne"] = "将手牌调整至一张",
  ["lvgu_changeHanCardThree"] = "将手牌调整至三张",
  ["lvgu_Use"] = "可以使用观看的一张牌",
  ["lvgu_loseHp"] = "失去1点体力",
  ["#lvgu_viewAndChoose"] = "履骨",
  ["#lvgu_viewAndChoose&"] = "牌堆底",
  ["#lvgu_useOne"] = "你可以使用其中一张不为【杀】的牌",
  ["#lvgu_Choose"] = "履骨：请选择一项",
  ["@@lvgu_three-turn"] = "履骨 摸至一",
  ["@@lvgu_one-turn"] = "履骨 摸至三",
}
louxuan:addSkill(linji)
louxuan:addSkill(lvgu)
return extension 